package com.example.demo.checkReport.service.impl;

import com.example.demo.checkReport.entity.CheckForm;
import com.example.demo.checkReport.entity.PageCheckForm;
import com.example.demo.checkReport.mapper.CheckFormMapper;
import com.example.demo.checkReport.service.CheckFormService;
import com.example.demo.common.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lbyani
 * @since 2021-05-25
 */
@Service
public class CheckFormServiceImpl extends ServiceImpl<CheckFormMapper, CheckForm> implements CheckFormService {

	@Autowired
	private CheckFormMapper formMapper;
	
	@Override
	public ResponseData selFormById(int headId, int currentPage, int pageSize) {
		// TODO Auto-generated method stub
		QueryWrapper<CheckForm> wrapper = new QueryWrapper<CheckForm>();
		wrapper.eq("head_id", headId);
		
		// 根据currentPage 和 PageSize 查询信息
		Page<CheckForm> page = new Page<CheckForm>(currentPage,pageSize);
		
		PageCheckForm results = new PageCheckForm();
		
		try {
			IPage<CheckForm> formIPage = formMapper.selectPage(page, wrapper);
			
			// 获取所有数据
			results.setCheckFormLists(formIPage.getRecords());
			
			// 获取总页数
			results.setPagecount(formIPage.getPages());
			
			// 获取总记录数
			results.setTotal(formIPage.getTotal());
			
			
		} catch (Exception e) {
			// TODO: handle exception
			System.out.println(e);
			return ResponseData.buildError("查询失败！");
		}
		
		return ResponseData.buildOk(results);
	}

}
